/************************************************************************************/
/*  Program name CAPFNDIMP_ORG_INFO.sql                                             */
/*  Creater:  WONG Wing Kin (PCCW - UniHub)                                         */
/*************   History   *************************                                */
/* 30 NOV, 2005   WONG Wing Kin         First created                               */
/************************************************************************************/
SET SERVEROUTPUT ON SIZE 1000000;

--ALTER TRIGGER HR_ORGANIZATION_INFORMATIO_OVN DISABLE;
--ALTER TRIGGER HR_ORGANIZATION_INFORMATIO_WHO DISABLE;
--ALTER TRIGGER HR_ORG_INFO_ARI DISABLE;
--ALTER TRIGGER HR_ORG_INFO_BRI DISABLE;
--ALTER TRIGGER HR_PA_MAINTN_ORG_HIST_BRD DISABLE;
--ALTER TRIGGER HR_PA_MAINTN_ORG_HIST_BRI DISABLE;
--ALTER TRIGGER HR_PA_MAINTN_ORG_HIST_BRU DISABLE;
--ALTER TRIGGER HR_PA_MAIN_ORG_INFO_HIST_BRI DISABLE;

DECLARE
	lv_Prog_ID		VARCHAR2(100)	:=	'CAPFNDIMP_ORG_INFO';

	lv_Scc_Count	NUMBER			:=	0;
	lv_Err_Count	NUMBER			:=	0;
	lv_Err_Msg		VARCHAR2(500)	:=	'No Error';

	CURSOR Cur_F IS
	SELECT
		*
	FROM
		CRST_FND_ORG_INFO;

	lv_Next_Seq_ID	NUMBER;

BEGIN

	FOR C1 IN Cur_F LOOP
		BEGIN
			SELECT	HR_ORGANIZATION_INFORMATION_S.NextVal
			INTO	lv_Next_Seq_ID
			FROM	DUAL;

			INSERT INTO CRST_FND_ORG_INFO_MAP VALUES
			(
			C1.ORGANIZATION_ID,
			lv_Next_Seq_ID
			);

			INSERT INTO HR_ORGANIZATION_INFORMATION
			VALUES
			(
			lv_Next_Seq_ID,									--ORG_INFORMATION_ID,
			C1.ORG_INFORMATION_CONTEXT,
			CAPBRIMP_MAPPING.GetOrgMapping(C1.ORGANIZATION_ID),
			C1.ORG_INFORMATION1,
			C1.ORG_INFORMATION10,
			C1.ORG_INFORMATION11,
			C1.ORG_INFORMATION12,
			C1.ORG_INFORMATION13,
			C1.ORG_INFORMATION14,
			C1.ORG_INFORMATION15,
			C1.ORG_INFORMATION16,
			C1.ORG_INFORMATION17,
			C1.ORG_INFORMATION18,
			C1.ORG_INFORMATION19,
			C1.ORG_INFORMATION2,
			C1.ORG_INFORMATION20,
			C1.ORG_INFORMATION3,
			C1.ORG_INFORMATION4,
			C1.ORG_INFORMATION5,
			C1.ORG_INFORMATION6,
			C1.ORG_INFORMATION7,
			C1.ORG_INFORMATION8,
			C1.ORG_INFORMATION9,
			C1.REQUEST_ID,
			C1.PROGRAM_APPLICATION_ID,
			C1.PROGRAM_ID,
			C1.PROGRAM_UPDATE_DATE,
			C1.ATTRIBUTE_CATEGORY,
			C1.ATTRIBUTE1,
			C1.ATTRIBUTE2,
			C1.ATTRIBUTE3,
			C1.ATTRIBUTE4,
			C1.ATTRIBUTE5,
			C1.ATTRIBUTE6,
			C1.ATTRIBUTE7,
			C1.ATTRIBUTE8,
			C1.ATTRIBUTE9,
			C1.ATTRIBUTE10,
			C1.ATTRIBUTE11,
			C1.ATTRIBUTE12,
			C1.ATTRIBUTE13,
			C1.ATTRIBUTE14,
			C1.ATTRIBUTE15,
			C1.ATTRIBUTE16,
			C1.ATTRIBUTE17,
			C1.ATTRIBUTE18,
			C1.ATTRIBUTE19,
			C1.ATTRIBUTE20,
			C1.LAST_UPDATE_DATE,
			CAPBRIMP_COMMON.GetUser(C1.LAST_UPDATED_NAME),	--LAST_UPDATED_BY,
			C1.LAST_UPDATE_LOGIN,
			CAPBRIMP_COMMON.GetUser(C1.CREATED_NAME),		--CREATED_BY,
			C1.CREATION_DATE,
			C1.OBJECT_VERSION_NUMBER,
			C1.PARTY_ID
			);
		EXCEPTION
			WHEN OTHERS THEN
				DBMS_OUTPUT.Put_Line(SQLERRM);
				lv_Err_Count	:=	lv_Err_Count + 1;
		END;
		lv_Scc_Count	:=	lv_Scc_Count	+	1;
	END LOOP;

	IF	lv_Err_Count	>	0	THEN
		ROLLBACK;
	END IF;

	INSERT INTO CAPCNV_LOG(
		PROG_ID,
		PROCESS_DATE,
		RECORD_PROCESSED,
		RECORD_REJECTED,
		RECORD_EXTRACTED,
		ERR_MSG
	) VALUES (
		lv_Prog_ID,
		SYSDATE,
		lv_Scc_Count,
		lv_Err_Count,
		lv_Scc_Count-lv_Err_Count,
		lv_Err_Msg
	);

	COMMIT;
END;
/

--ALTER TRIGGER HR_ORGANIZATION_INFORMATIO_OVN ENABLE;
--ALTER TRIGGER HR_ORGANIZATION_INFORMATIO_WHO ENABLE;
--ALTER TRIGGER HR_ORG_INFO_ARI ENABLE;
--ALTER TRIGGER HR_ORG_INFO_BRI ENABLE;
--ALTER TRIGGER HR_PA_MAINTN_ORG_HIST_BRD ENABLE;
--ALTER TRIGGER HR_PA_MAINTN_ORG_HIST_BRI ENABLE;
--ALTER TRIGGER HR_PA_MAINTN_ORG_HIST_BRU ENABLE;
--ALTER TRIGGER HR_PA_MAIN_ORG_INFO_HIST_BRI ENABLE;
